import os

def read_csv(self, filepath):
    # os.path.exists判断文件是否存在
    if os.path.exists(filepath):
        with open(filepath, encoding='utf-8') as file:
            content = file.readlines()
        key_list = []
        data_list = []
        for row in range(len(content)):
            # 跳过以#号开头的行及空行
            if content[row].startswith('#') or content[row] == '\n':
                continue
            elif key_list == []:
                key_list = content[row].strip().split(',')
            else:
                value_list = content[row].strip().split(',')
                info = dict(zip(key_list, value_list))
                data_list.append(info)
        return data_list
    else:
        return False

def read_csv2(filepath):
    # if os.path.exists(filepath):
    with open(filepath,encoding="utf-8") as file:
        content=file.readlines()
        print(content)




def read_csv3():
    with open("ceshi.csv",encoding='utf-8') as file:
        content = file.readlines()
    list = []
    for line in content:
        if line.startswith('#'):
            continue
        dict = {}
        dict['leixin'] = line.strip().split(',')[0]
        dict['name'] = line.strip().split(',')[1]
        list.append(dict)
    return list

def test_login(self):
    for user in read_csv3():
        self.login.do_login(user['username'], user['password'])

        if user['result'] == 'ok':
            try:
                self.common.logout_link()
                util.write_result('登录测试', '成功')
                # self.common.decode()
                self.common.logout_link().click()
                print("登陆测试成功")
            except:
                util.write_result('登录测试', '失败')
                print("登录测试失败")
        else:
            try:
                self.login.login_fail_tip()
                util.write_result('登录测试', '成功')
                print("登录测试成功")
            except:
                util.write_result('登录测试', '失败')
                print("登录测试失败")

read_csv3("ceshi.csv")
print(list)
# print(list)

    # else:
    #     return False